<?php

Raise::load('core.RaiseObject');
Raise::load('core.collection.RaiseCollection');

/**
 * RaiseClass class
 * Class / Object related functionality
 *
 * @author Sam-Mauris Yong / hellclanner at live dot com
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package phpraise.core.reflection
 * @since 1.2
 */
class RaiseClass extends RaiseObject{
    
    /**
     * The class name
     * @var string
     */
    private $class;
    
    /**
     * Create a new RaiseClass object
     * @param string|object $class The class or object (class instance)
     */
    public function __construct($class){
        if(is_object($class)){
            $class = get_class($class);
        }
        $this->class = $class;
    }
    
    /**
     * Get the name of the class
     * @return string
     */
    public function name(){
        return $this->class;
    }
    
    /**
     * Get a collection of all the public accessible methods in the class
     * @return RaiseCollection 
     */
    public function methods(){
        $a = get_class_methods($this->class);
        return new RaiseCollection($a);
    }
    
    /**
     * Get a collection of all the public accessible properties in the class
     * @return RaiseCollection 
     */
    public function properties(){
        $a = get_class_vars($this->class);
        return new RaiseCollection($a);
    }
    
    /**
     * Check if the class exists / has been defined
     * @return boolean
     */
    public function exists(){
        return class_exists($this->class);
    }
    
    /**
     * Get the name of the parent class
     * @return string
     */
    public function parent(){
        return get_parent_class($this->class);
    }
    
    /**
     * Check if this class is a sub-class of another
     * @param string $parent
     * @return boolean
     */
    public function isSubclass($parent){
        return is_subclass_of($this->class, $parent);
    }
    
    /**
     * Get a collection of interfaces that this class implements
     * @return RaiseCollection 
     */
    public function implementations(){
       $a = class_implements($this->class);
        return new RaiseCollection($a);
    }
    
    /**
     * Create an alias for this class
     * @param $name The new alias for this class
     * @return RaiseClass The RaiseClass object of the alias name
     */
    public function alias($name){
        class_alias($this->class, $name);
        return new RaiseClass($name);
    }
    
}
